package com.example.rbacmanage.controller.background;

import com.example.rbacmanage.common.Result;
import com.example.rbacmanage.entity.app.FriendshipLink;
import com.example.rbacmanage.service.app.FriendshipLinkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping("/background/friendshipLink")
public class FriendshipLinkController{

    @Autowired
    private FriendshipLinkService friendshipLinkService;

    @GetMapping("/list")
    @PreAuthorize("hasAnyAuthority('background:friendshipLink:list')")
    public Result page(FriendshipLink friendshipLink){
        return Result.success(friendshipLinkService.getPage(friendshipLink));
    }


    @GetMapping("/{id}")
    public Result getInfo(@PathVariable Long id){
        return Result.success(friendshipLinkService.getById(id));
    }

    @PreAuthorize("hasAnyAuthority('background:friendshipLink:add')")
    @PostMapping("/add")
    public Result add(@RequestBody FriendshipLink friendshipLink){
        friendshipLink.setCreateTime(new Date());
        friendshipLinkService.save(friendshipLink);
        return Result.success();
    }
    @PreAuthorize("hasAnyAuthority('background:friendshipLink:update')")
    @PutMapping("/update")
    public Result update(@RequestBody FriendshipLink friendshipLink){
        friendshipLinkService.update(friendshipLink);
        return Result.success();
    }

    @PreAuthorize("hasAnyAuthority('background:friendshipLink:remove')")
    @DeleteMapping("/remove")
    public Result remove(@RequestBody Long[] ids){
        friendshipLinkService.remove(ids);
        return Result.success();
    }
}
